package journalarray;

import java.util.*;

/**
 * This is realization for interface Comparator
 * main function is sort by importance, source and date
 * @author Евгений
 */
public class SortByImportanceSourceDate implements Comparator<Record> {

    @Override
    public int compare(Record o1, Record o2) {
        if (o1.getImportance().ordinal() > o2.getImportance().ordinal()) {
            return 1;
        }
        
        if (o1.getImportance().ordinal() < o2.getImportance().ordinal()) {
            return -1;
        }
        
        int comp = 0;
        
        if ((comp = o1.getSource().compareTo(o2.getSource())) != 0) {
            return comp;
        }
        
        if (o1.getTime().after(o2.getTime())) {
            return 1;
        }
        
        if (o2.getTime().after(o1.getTime())) {
            return -1;
        }
        
        return 0;
    }
}
